package com.liu.common.service.impl;

import cn.dev33.satoken.stp.StpInterface;
import com.liu.user.entity.dto.UserPermissionInfoDTO;
import com.liu.user.service.IUserPermissionInfoService;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.List;
import java.util.stream.Collectors;

@Component
public class StpInterfaceImpl implements StpInterface {

    @Resource
    private IUserPermissionInfoService userPermissionInfoService;

    /**
     * 权限
     * @param o 登录id
     * @param s
     * @return 权限集合
     */
    @Override
    public List<String> getPermissionList(Object o, String s) {
        String userId = String.valueOf(o);
        // 获取当前用户的所有权限
        List<UserPermissionInfoDTO> userPermissionList = userPermissionInfoService.getUserPermission(userId);
        return userPermissionList.stream().map(UserPermissionInfoDTO::getPermissionCode).collect(Collectors.toList());
    }

    /**
     * 角色
     * @param o 登录id
     * @param s
     * @return 角色集合
     */
    @Override
    public List<String> getRoleList(Object o, String s) {
        return null;
    }
}
